using System;
using System.Collections.Generic;
using System.Text;

namespace Eve.Data
{
    public class Bloodline : EveProperty
    {
        private string bloodlineName;
        private int raceId;
        private string description;
        private string maleDescription;
        private string femaleDescription;
        private int shipTypeId;
        private int corporationId;
        private int perception;
        private int willpower;
        private int charisma;
        private int memory;
        private int intelligence;
        private List<int> skillTypeIds = new List<int>();
        private int graphicId;
        private string shortDescription;
        private string shortMaleDescription;
        private string shortFemaleDescription;

        private Race race;
        private Type shipType;
        private Corporation corporation;
        private List<Type> skillTypes;
        private Graphic graphic;

        public string Name
        {
            get { return bloodlineName; }
        }
        public Race Race
        {
            get
            {
                if (race == null)
                    race = new Race(db, raceId);
                return race;
            }
        }
        public string Description
        {
            get { return description; }
        }
        public string MaleDescription
        {
            get { return maleDescription; }
        }
        public string FemaleDescription
        {
            get { return femaleDescription; }
        }
        public Type Ship
        {
            get
            {
                if (shipType == null)
                    shipType = new Type(db, shipTypeId);
                return shipType;
            }
        }
        public Corporation Coporation
        {
            get
            {
                if (corporation == null)
                    corporation = new Corporation(db, corporationId);
                return corporation;
            }
        }
        public int Perception
        {
            get { return perception; }
        }
        public int Willpower
        {
            get { return willpower; }
        }
        public int Charisma
        {
            get { return charisma; }
        }
        public int Memory
        {
            get { return memory; }
        }
        public int Intelligence
        {
            get { return intelligence; }
        }
        public List<Type> Skills
        {
            get
            {
                if (skillTypes == null)
                {
                    skillTypes = new List<Type>();
                    foreach (int id in skillTypeIds)
                        skillTypes.Add(new Type(db, id));
                }
                return skillTypes;
            }
        }
        public Graphic Graphic
        {
            get
            {
                if (graphic == null)
                    graphic = new Graphic(db, graphicId);
                return graphic;
            }
        }
        public string ShortDescription
        {
            get { return shortDescription; }
        }
        public string ShortMaleDescription
        {
            get { return shortMaleDescription; }
        }
        public string ShortFemaleDescription
        {
            get { return shortFemaleDescription; }
        }

        internal Bloodline(DbDataRow dr)
            : base(dr.Database, EvePropertyType.Bloodline, dr["bloodlineID"])
        {
            Fill(dr);
        }
        internal Bloodline(Database db, int id)
            : base(db, EvePropertyType.Bloodline, id)
        {
            Fill(db.ExecuteSingle("SELECT * FROM chrBloodlines WHERE bloodlineID=" + id));
        }

        private void Fill(DbDataRow dr)
        {
            bloodlineName = dr["bloodlineName"];
            raceId = dr["raceID"];
            description = dr["description"];
            maleDescription = dr["maleDescription"];
            femaleDescription = dr["femaleDescription"];
            shipTypeId = dr["shipTypeID"];
            corporationId = dr["corporationID"];
            perception = dr["perception"];
            willpower = dr["willpower"];
            charisma = dr["charisma"];
            memory = dr["memory"];
            intelligence = dr["intelligence"];
            skillTypeIds.Add(dr["skillTypeID1"]);
            skillTypeIds.Add(dr["skillTypeID2"]);
            graphicId = dr["graphicID"];
            shortDescription = dr["shortDescription"];
            shortMaleDescription = dr["shortMaleDescription"];
            shortFemaleDescription = dr["shortFemaleDescription"];
        }
    }
}
